package cn.it.infrastructure.domain.service.impl;

import cn.it.infrastructure.domain.service.ITypeService;
import cn.it.infrastructure.domain.valobj.ProductSortVO;
import cn.it.infrastructure.mapper.IGoodsMapper;
import cn.it.infrastructure.mapper.ITypeMapper;
import cn.it.infrastructure.po.TbGoods;
import cn.it.infrastructure.po.TbType;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Mzq
 * @description
 * @createTime 2024/7/5
 */
@Service
public class TypeServiceImpl implements ITypeService {

   private ITypeMapper typeMapper;

   private IGoodsMapper goodsMapper;

    public TypeServiceImpl(ITypeMapper typeMapper, IGoodsMapper goodsMapper) {
        this.typeMapper = typeMapper;
        this.goodsMapper = goodsMapper;
    }


    @Override
   public List<ProductSortVO> productSort() {
      List<TbType> sortList = typeMapper.selectName();
      List<ProductSortVO> sortVOList = new ArrayList<>(sortList.size());
      for (TbType tbType : sortList) {
         ProductSortVO sortVO = ProductSortVO.builder()
                  .id(tbType.getId())
                  .name(tbType.getName())
                 .businessId(tbType.getBusinessId())
                  .build();
         sortVOList.add(sortVO);
      }

      return sortVOList;
   }

    @Override
    public List<TbGoods> queryGoodsByBusinessId(Long businessId) {

        List<TbGoods> goods = goodsMapper.queryGoodsByBusinessId(businessId);

        return goods;

    }
}
